package com.cenwangkeji.zhihuimuye.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.cenwangkeji.zhihuimuye.R;
import com.cenwangkeji.zhihuimuye.utils.DynamicLineChartManager;
import com.cenwangkeji.zhihuimuye.utils.PieChartUtil;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.lws.basic.base.BaseFragment;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @松 on 2019/10/9 11:00
 */
public class HomeFragment extends BaseFragment {
    @BindView(R.id.banner)
    Banner mBanner;
    @BindView(R.id.pie_chart)
    PieChart mPieChart;
    Unbinder unbinder;


    @Override
    public int setLayoutId() {
        return R.layout.fragment_home;
    }

    private void initBanner(){
        List<Integer> list = new ArrayList<>();
        list.add(R.mipmap.bg_banner_3);
        list.add(R.mipmap.bg_banner_1);
        list.add(R.mipmap.bg_banner_2);
        List<String> title = new ArrayList<>();
        title.add("阿荣旗扶贫牧场");
        title.add("阿荣旗扶贫牧场");
        title.add("阿荣旗扶贫牧场");
        mBanner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {

                    Uri uri = Uri.parse("http://news.cctv.com/2019/10/10/ARTIKi6JwN06c0dAYHh8QX50191010.shtml");
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);


            }
        });
        mBanner.setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                Glide.with(context).load(path).into(imageView);
            }

        }).setImages(list).setBannerTitles(title).setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE).setDelayTime(3000).start();

    }



    @Override
    protected void initView(View view) {
        super.initView(view);
        unbinder = ButterKnife.bind(this, view);
        initBanner();
        HashMap dataMap=new HashMap();
        dataMap.put("公牛","1579");
        dataMap.put("母牛","3421");
        PieChartUtil.getPitChart().setPieChart(mPieChart,dataMap,"公母牛百分比",true);

    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


}
